Release 10.1A: OpenEdge Development:
ADM and SmartObjects
Writing super procedures
Another task you perform when you extend the ADM, whether by creating a new class or by customizing an existing class, is writing super procedures; that is, adding to the super procedure file custom functions and/or internal procedures that support the special behavior of your class. If you are creating a new class, you do this for the standard super procedure file. If you are customizing an existing class, you do it for the custom super procedure file.
Two important points to keep in mind when writing any functions or internal procedures that go into an ADM super procedure are:
References in super procedures to other procedures
When you write the functions or internal procedures that go into an ADM super procedure, keep in mind there is nothing about a super procedure that identifies it as a super procedure. It is simply a Progress procedure file that is run as a persistent procedure and then added as a super procedure to some other running procedure. The source code or compiled r-code for a super procedure contains nothing special that identifies it as a super procedure.
What is special about a super procedure is the style of the code within its functions and internal procedures, which must account for the fact that these entry points are run on behalf of some other procedure. ADM super procedures, therefore, always must refer to the procedure on whose behalf they run. The basic mechanism is the
TARGET-PROCEDUREbuilt-in function, which evaluates to the procedure handle of the procedure from which the entry point originally was invoked. The{get}and{set}include files, which provide a pseudo-syntax for getting and setting ADM properties, support this mechanism by always referring back to theTARGET-PROCEDURE, so you always should use{get}and{set}when writing property references in super procedures. In addition, these include files identify whether a given property can be accessed directly out of the ADMProps temp-table record in theTARGET-PROCEDUREor instead requires the execution of the actualgetpropnameorsetpropnamefunction. For detailed information on these property mechanisms, see the "{get} and {set} pseudo-syntax for object properties" section, and the "Get and set functions for object properties" section.For example, an internal procedure that operates on the
RowObjectbuffer handle of itsTARGETbegins by retrieving that property value:
To retrieve the value of a property from an object other than the
TARGET-PROCEDURE, you can specify an optional final argument for the{get}and{set}include files that is the object’s procedure handle. For example, the following code gets the value of theEnabledTablesproperty from the Data-Source of theTARGET-PROCEDURE:
You also can use the include file
{fn}as a convenient way to invoke a function inTARGET-PROCEDURE; for example:
Similarly, the variant
{fnarg}invokes a function that takes a single argument; for example:
Shared super procedures
ADM super procedures are designed to be shared among all running instances of the SmartObjects that use that procedure.
Note: It is possible to create a super procedure intended to serve exactly one running procedure at a time, but this is not the correct design for super procedures that are part of the ADM class hierarchy and that are started in the standard way (that is, by runningstart-super-procin the ADM include files).Because ADM super procedures are shared, you must ensure their code never assumes continuity between calls. If a particular operation involves executing two entry points in a super procedure, the code should not share property values between calls (whether by using local variables defined in the
Definitionssection or by using another technique); instead, it should retrieve any property values needed at the top of each entry point. Although this might seem slightly inefficient, using{get}to retrieve a property value from the property temp-table compiles into a single in-line Progress 4GLASSIGNstatement and is quite fast. Using this technique assures your super procedures can be shared among all running instances of your new class.Likewise, because super procedures operate on behalf of other procedures, you always must
PUBLISHeventsFROMTARGET-PROCEDURE. If you do not do this, your event normally will not have any effect, because the SmartObjects will not have subscribed to that event in the super procedure itself.Also, when you invoke one entry point in a super procedure from another, you must preserve the value of
TARGET-PROCEDUREin the called entry point. For example, suppose your super procedure contains two procedures,ProcAandProcB, and you want to runProcBfromProcAin that super procedure. You have basically two choices, depending on whetherProcBis aPRIVATEinternal procedure or function that should never be run from any other procedure, or an entry point you might want to run or to override from itsTARGET-PROCEDUREor another procedure:
- If
ProcBis aPRIVATEinternal procedure or function, one that should never be run from any other procedure,ProcAcan runProcBdirectly. In this case, ifProcBmust refer to the target procedure (to get a property value, for example):
TARGET-PROCEDUREmust be passed as an input parameter toProcB.ProcBmust not use{get}or{set}to access the property.This is because the value of
TARGET-PROCEDUREinsideProcBwill not beTARGET-PROCEDURE—it will be the super procedure’s procedure handle, since it was executed directly from the super procedure. In such a case, it is normally better to pass any property values toProcBfromProcA. The following two examples, which illustrate code inProcA, show two ways to do this:
- If
ProcBis an entry point that you might want to run or override from itsTARGET-PROCEDUREor another procedure,ProcAshould invokeProcBINTARGET-PROCEDUREeven though they are located in the same super procedure. In this way, references toTARGET-PROCEDURE insideProcBcorrectly evaluate to the handle of the SmartObject that causedProcAto be invoked. (This also makes it possible to overrideProcBin a SmartObject, if this is necessary and appropriate.) The following example, which illustrates code inProcA, shows how to do this:
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |